﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server
{
    public class math
    {
        public static string[][] Permutations(string[] arr)
        {
            List<string[]> list = new List<string[]>();
            foreach (string s in arr)
            {
                List<string[]> lst = list.GetRange(0, list.Count);
                string[] nArr = { s };
                list.Add(nArr);
                foreach (string[] ss in lst)
                {
                    list.Add(ss.Concat(nArr).ToArray());
                }
            }
            List<string[]> outList = list.OrderByDescending(p => p.Length).ToList();
            //  outList.ForEach(p => Console.WriteLine(string.Join(",", p)));
            return outList.ToArray();
        }
    }
}

